local zishucup__suqi = fk.CreateSkill{
  name = "zishucup__suqi",
}

Fk:loadTranslationTable{
  ["zishucup__suqi"] = "肃齐",
  [":zishucup__suqi"] = "你受到或造成伤害后，你可以令伤害来源选择是否与受伤角色拼点。结算后，你将放弃拼点或没赢的角色的一张牌置于牌堆顶或牌堆底。",

  ["#zishucup__suqi-choice"] = "肃齐：请选择一项！",
  ["zishucup__suqi_top"] = "置于牌堆顶",
  ["zishucup__suqi_bottom"] = "置于牌堆底",
  ["#zishucup__suqi-chooose"] = "肃齐：请将选择的牌置于牌堆顶或底！",
  ["zishucup__suqi1"] = "与受伤角色 %dest 拼点，没赢者被执行下一项",
  ["zishucup__suqi2"] = "令技能发动者将你的一张牌置于牌堆顶或牌堆底",

  ["$zishucup__suqi1"] = "精达事机，威恩兼著，肃齐万里！",
  ["$zishucup__suqi2"] = "讨伐匈奴，斩首鲜卑，以清宇内！",
}

local spec = {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(zishucup__suqi.name) and target == player then
      return data.from and not data.from.dead and data.to and not data.to.dead
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"zishucup__suqi1::"..data.to.id, "zishucup__suqi2"}
    if not data.from:canPindian(data.to) then table.removeOne(choices, "zishucup__suqi1::"..data.to.id) end
    local choice = room:askToChoice(data.from, {
      choices = choices,
      skill_name = zishucup__suqi.name,
      prompt = "#zishucup__suqi-choice",
    })
    if choice ~= "zishucup__suqi2" then
      local pindian = data.from:pindian({data.to}, self.name)
      for _, p in ipairs ({data.from, data.to}) do
        if pindian.results[data.to].winner ~= p and not p:isNude() and not player.dead then
          local chosen = room:askToChooseCard(player, { target = p, flag = "he", skill_name = zishucup__suqi.name })
          local choices2 = {"zishucup__suqi_top", "zishucup__suqi_bottom"}
          local choicess = room:askToChoice(player, {
            choices = choices2,
            skill_name = zishucup__suqi.name,
            prompt = "#zishucup__suqi-chooose",
          })
          if choicess == "zishucup__suqi_top" then
            room:moveCards({
              ids = {chosen},
              from = p,
              toArea = Card.DrawPile,
              moveReason = fk.ReasonPut,
              skillName = zishucup__suqi.name,
              proposer = player,
              moveVisible = true
            })
          else
            room:moveCards({
              ids = {chosen},
              from = p,
              toArea = Card.DrawPile,
              moveReason = fk.ReasonPut,
              skillName = zishucup__suqi.name,
              proposer = player,
              moveVisible = true,
              drawPilePosition = -1
            })
          end
        end
      end
    else
      if data.from:isNude() or player.dead then return end
      local chosen = room:askToChooseCard(player, { target = data.from, flag = "he", skill_name = zishucup__suqi.name })
      local choices2 = {"zishucup__suqi_top", "zishucup__suqi_bottom"}
      local choicess = room:askToChoice(player, {
        choices = choices2,
        skill_name = zishucup__suqi.name,
        prompt = "#zishucup__suqi-chooose",
      })
      if choicess == "zishucup__suqi_top" then
        room:moveCards({
          ids = {chosen},
          from = data.from,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = zishucup__suqi.name,
          proposer = player,
          moveVisible = true
        })
      else
        room:moveCards({
          ids = {chosen},
          from = data.from,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = zishucup__suqi.name,
          proposer = player,
          moveVisible = true,
          drawPilePosition = -1
        })
      end
    end
  end,
}

zishucup__suqi:addEffect(fk.Damage, spec)
zishucup__suqi:addEffect(fk.Damaged, spec)

return zishucup__suqi
